"""
1.打开Tpshop首页;

2.使用Xpath文本定位策略定位登陆超链接,并点击;

3.使用Xpath属性定位策略定位用户名输入框,输入:15800000001;

4.使用Xpath属性包含定位策略定位密码输入框,输入:123456;

5.使用Xpath属性与逻辑结合策略定位验证码输入框,输入:8888;

6.使用Xpath层级与属性结合策略定位登陆按钮,并点击;

每步操作之后暂停2s
"""
import time

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

drive = webdriver.Chrome()
# drive.implicitly_wait(10)#隐式等待
# 打开Tpshop首页;
drive.get("https://www.tp-shop.cn/")
#全屏
drive.maximize_window()
# 使用Xpath文本定位策略定位登陆超链接,并点击
login_item = WebDriverWait(drive,60).until(EC.presence_of_element_located((By.XPATH,'//a[contains(text(),"登录")]')))
# login_item = drive.find_element(By.XPATH,'//a[contains(text(),"登录")]')
login_item.click()
time.sleep(2)
# 使用Xpath属性定位策略定位用户名输入框,输入:15800000001;
# username = WebDriverWait(drive,10).until(EC.presence_of_element_located((By.XPATH,'//input[@name="username"]')))
username = WebDriverWait(drive,10).until(EC.presence_of_element_located((By.CSS_SELECTOR,'input[name="username"]')))
username.send_keys('15800000001')
# 使用Xpath属性包含定位策略定位密码输入框,输入:123456
password = WebDriverWait(drive,10).until(EC.presence_of_element_located((By.XPATH,'//input[@name="password"]')))
password.send_keys('123456')
time.sleep(2)
# 使用Xpath属性与逻辑结合策略定位验证码输入框,输入:8888;
verifycode = drive.find_element(By.XPATH,'//input[@type="text" and @name="verify_code"]')
verifycode.send_keys("8888")
# 使用Xpath层级与属性结合策略定位登陆按钮,并点击
login = drive.find_element(By.XPATH,'//input[@type="submit"]')
login.click()
time.sleep(2)
# input("按回车结束")
confirm = drive.find_element(By.CLASS_NAME,'layui-layer-btn0')
confirm.click()
time.sleep(2)
